package com.hong.spring.propertis.config;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
/**
 *
 * 功能描述:通过继承 PropertyPlaceholderConfigurer 修改指定的账号名和密码进行加解密
 *
 * @param:
 * @return:
 * @auther: csh
 * @date: 2020/8/10 16:29
 */
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
	private String[] encryptPropNames ={"jdbc.user","jdbc.password"};
	
	@Override
	protected String convertProperty(String propertyName, String propertyValue) {
		if(isEncryptProp(propertyName)){
			String decryptValue = DESUtils.getDecryptString(propertyValue);
			System.out.println(decryptValue);
			return decryptValue;
		}else{
			return propertyValue;
		}
	}
	
	/**
	 * 判断是否是加密的属性
	 * @param propertyName
	 * @return
	 */
	private boolean isEncryptProp(String propertyName){
		for(String encryptPropName:encryptPropNames){
			if(encryptPropName.equals(propertyName)){
				return true;
			}
		}
		return false;
	}
}
